

package Formularios;



import Clases.ConexionMySql;
import Clases.Funcionario;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


public class funcionario extends javax.swing.JFrame {
   private DefaultTableModel busqueda;

    public funcionario() {
        initComponents();
        llamar();
        
        id_funcionario.setEnabled(false);
        nombre_funcionario.setEnabled(false);
        ci_funcionario.setEnabled(false);
        correo_funcionario.setEnabled(false);
        cargo_funcionario.setEnabled(false);
        usuario_funcionario.setEnabled(false);
        clave_funcionario.setEnabled(false);
        ingreso_funcionario.setEnabled(false);
        agregar_funcionario.setEnabled(false);
        eliminar_funcionario.setEnabled(false);
        editar_funcionario.setEnabled(false);
        
    }

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        id_funcionario = new javax.swing.JTextField();
        nombre_funcionario = new javax.swing.JTextField();
        ci_funcionario = new javax.swing.JTextField();
        correo_funcionario = new javax.swing.JTextField();
        cargo_funcionario = new javax.swing.JTextField();
        usuario_funcionario = new javax.swing.JTextField();
        eliminar_funcionario = new javax.swing.JButton();
        agregar_funcionario = new javax.swing.JButton();
        editar_funcionario = new javax.swing.JButton();
        nuevo_funcionario = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        ingreso_funcionario = new com.toedter.calendar.JDateChooser();
        clave_funcionario = new javax.swing.JPasswordField();
        jLabel9 = new javax.swing.JLabel();
        atras = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        vista = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        funcionario_busqueda = new javax.swing.JTextField();
        buscar_nombre = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(0));

        jLabel1.setText("ID:");

        jLabel2.setText("Nombre y Apellido:");

        jLabel4.setText("C.I.:");

        jLabel5.setText("Cargo:");

        jLabel6.setText("Clave:");

        jLabel7.setText("Correo:");

        jLabel8.setText("Usuario:");

        id_funcionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                id_funcionarioActionPerformed(evt);
            }
        });

        eliminar_funcionario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/excluded.png"))); // NOI18N
        eliminar_funcionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eliminar_funcionarioActionPerformed(evt);
            }
        });

        agregar_funcionario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/guardar.png"))); // NOI18N
        agregar_funcionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_funcionarioActionPerformed(evt);
            }
        });

        editar_funcionario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/editar.png"))); // NOI18N
        editar_funcionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editar_funcionarioActionPerformed(evt);
            }
        });

        nuevo_funcionario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/agregar.gif"))); // NOI18N
        nuevo_funcionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nuevo_funcionarioActionPerformed(evt);
            }
        });

        jLabel10.setText("Fecha de Ingreso:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(jLabel7)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel8)
                    .addComponent(jLabel6)
                    .addComponent(jLabel10))
                .addGap(42, 42, 42)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(nombre_funcionario, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
                                .addComponent(correo_funcionario)
                                .addComponent(usuario_funcionario)
                                .addComponent(cargo_funcionario)
                                .addComponent(id_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ci_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(ingreso_funcionario, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 117, Short.MAX_VALUE)
                        .addComponent(agregar_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(eliminar_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(editar_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nuevo_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(clave_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(eliminar_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(id_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(nombre_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(ci_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(correo_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(23, 23, 23)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(cargo_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(usuario_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(clave_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10)
                            .addComponent(nuevo_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(editar_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(agregar_funcionario)
                            .addComponent(ingreso_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 30)); // NOI18N
        jLabel9.setText("Funcionario");

        atras.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/close.png"))); // NOI18N
        atras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atrasActionPerformed(evt);
            }
        });

        vista.setBackground(new java.awt.Color(204, 204, 204));
        vista.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Identificador", "Nombre", "CI o RUC", "Correo", "Cargo", "Usuario", "Clave", "Fecha de Ingreso"
            }
        ));
        vista.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                vistaMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(vista);
        vista.getColumnModel().getColumn(6).setMinWidth(20);

        jLabel3.setText("Nombre: ");

        buscar_nombre.setText("Buscar");
        buscar_nombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscar_nombreActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(78, 78, 78)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(funcionario_busqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(29, 29, 29)
                                .addComponent(buscar_nombre)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(atras))
                            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(98, 98, 98))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(197, 197, 197)
                        .addComponent(jLabel9)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(funcionario_busqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(buscar_nombre))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(atras, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
                        .addGap(35, 35, 35))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void atrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atrasActionPerformed
        llamarprincipal();
        // TODO add your handling code here:
    }//GEN-LAST:event_atrasActionPerformed

    private void editar_funcionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editar_funcionarioActionPerformed
        ConexionMySql con= new ConexionMySql();
        Connection reg= con.conectar();
        System.out.println("Conexion establecida");
        SimpleDateFormat fecha= new SimpleDateFormat("yyyy-MM-dd");
        Funcionario funcionario = new Funcionario();
        funcionario.setId_funcionario(Integer.parseInt(id_funcionario.getText()));
        funcionario.setNombre(nombre_funcionario.getText());
        funcionario.setCi(Integer.parseInt(ci_funcionario.getText()));
        funcionario.setCorreo(correo_funcionario.getText());
        funcionario.setCargo(cargo_funcionario.getText());
        funcionario.setUsuario(usuario_funcionario.getText());
        funcionario.setClave(clave_funcionario.getText());
        funcionario.setFecha_ingreso(fecha.format(ingreso_funcionario.getDate()));
        String sql;
         sql="UPDATE funcionario"+" SET nombre=?,"+" ci=?,"+" correo=?,"+" cargo=?,"+" usuario=?,"+" clave=?, "+"fecha_ingreso=?"+" WHERE id_funcionario=?;";
        try {
            PreparedStatement pat=reg.prepareStatement(sql);
            
            pat.setString(1, funcionario.getNombre());
            pat.setInt(2,funcionario.getCi());
            pat.setString(3,funcionario.getCorreo());
            pat.setString(4,funcionario.getCargo());
            pat.setString(5,funcionario.getUsuario());
            pat.setString(6,funcionario.getClave());
            pat.setString(7,funcionario.getFecha_ingreso());
            pat.setInt(8,funcionario.getId_funcionario());
            pat.executeUpdate();
            
            JOptionPane.showMessageDialog(null, "Se Actualizo con Exito");
            
            llamar();
            limpiar();
            
        } catch (SQLException ex) {
            Logger.getLogger(funcionario.class.getName()).log(Level.SEVERE, null, ex);
        }  
        
    }//GEN-LAST:event_editar_funcionarioActionPerformed

    private void eliminar_funcionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eliminar_funcionarioActionPerformed
        ConexionMySql con= new ConexionMySql();
        Connection reg= con.conectar();
        System.out.println("Conexion establecida");
        
        Funcionario funcionario = new Funcionario();
        funcionario.setId_funcionario(Integer.parseInt(id_funcionario.getText()));

        String sql;
        sql = "DELETE FROM funcionario WHERE id_funcionario=?;";
        try {
            PreparedStatement pat = reg.prepareStatement(sql);
            pat.setInt(1,funcionario.getId_funcionario());
            pat.executeUpdate();

            JOptionPane.showMessageDialog(null, "Eliminacion Exitosa");
            
          llamar();
          limpiar();

        } catch (SQLException ex) {
            Logger.getLogger(clientes.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_eliminar_funcionarioActionPerformed

    private void nuevo_funcionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevo_funcionarioActionPerformed
    
        
        nombre_funcionario.setEnabled(true);
        ci_funcionario.setEnabled(true);
        correo_funcionario.setEnabled(true);
        cargo_funcionario.setEnabled(true);
        usuario_funcionario.setEnabled(true);
        clave_funcionario.setEnabled(true);
        ingreso_funcionario.setEnabled(true);
        agregar_funcionario.setEnabled(true);
        eliminar_funcionario.setEnabled(true);
        editar_funcionario.setEnabled(true);
        
        id_funcionario.setText("");
        nombre_funcionario.setText("");
        ci_funcionario.setText("");
        correo_funcionario.setText("");
        cargo_funcionario.setText("");
        usuario_funcionario.setText("");
        clave_funcionario.setText("");
        ingreso_funcionario.setDate(null);
        
    }//GEN-LAST:event_nuevo_funcionarioActionPerformed

    private void id_funcionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_id_funcionarioActionPerformed
           
    }//GEN-LAST:event_id_funcionarioActionPerformed

    private void agregar_funcionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_funcionarioActionPerformed
         ConexionMySql con= new ConexionMySql();
        Connection reg= con.conectar();
        System.out.println("Conexion establecida");
        SimpleDateFormat fecha= new SimpleDateFormat("yyyy-MM-dd");
        Funcionario funcionario = new Funcionario();
        //funcionario.setId_funcionario(Integer.parseInt(id_funcionario.getText()));
        funcionario.setNombre(nombre_funcionario.getText());
        funcionario.setCi(Integer.parseInt(ci_funcionario.getText()));
        funcionario.setCorreo(correo_funcionario.getText());
        funcionario.setCargo(cargo_funcionario.getText());
        funcionario.setUsuario(usuario_funcionario.getText());
        funcionario.setClave(clave_funcionario.getText());
        funcionario.setFecha_ingreso(fecha.format(ingreso_funcionario.getDate()) );
        String sql;
        sql="insert into funcionario (Nombre, Ci, Correo, Cargo, Usuario, Clave, Fecha_ingreso) values "+"(?,?,?,?,?,?,?);";
        try {
            PreparedStatement pat=reg.prepareStatement(sql);
            //pat.setInt(1,funcionario.getId_funcionario());
            pat.setString(1, funcionario.getNombre());
            pat.setInt(2,funcionario.getCi());
            pat.setString(3,funcionario.getCorreo());
            pat.setString(4,funcionario.getCargo());
            pat.setString(5,funcionario.getUsuario());
            pat.setString(6,funcionario.getClave());
            pat.setString(7,funcionario.getFecha_ingreso());
            
            int var=pat.executeUpdate();
                if (var > 0){
                   JOptionPane.showMessageDialog(null, "Se Registro Con exito");
                   llamar();
                } 
            limpiar();
            

        } catch (SQLException ex) {
            Logger.getLogger(funcionario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_agregar_funcionarioActionPerformed

    private void vistaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_vistaMouseClicked
      int filasel = vista.getSelectedRow();
        String valor = (String) busqueda.getValueAt(filasel,0);
        PasarTabla(valor);   
    }//GEN-LAST:event_vistaMouseClicked

    private void buscar_nombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscar_nombreActionPerformed

        ConexionMySql con = new ConexionMySql();
        Connection cnn = con.conectar();
        String[] titulos = {"Id Funcionario","Nombre","Doc Identidad","Correo","Cargo","Usuario","Clave","Fecha de Ingreso"};
        busqueda = new DefaultTableModel(null,titulos);
        String [] registro = new String[9];
        String id = (funcionario_busqueda.getText());
        String sql = "SELECT Id_funcionario,Nombre,Ci,Correo,Cargo,Usuario,Clave,Fecha_ingreso FROM funcionario where nombre LIKE '%" + id +"%'";
        try
        {
            Statement st = cnn.createStatement();
            ResultSet rs = st.executeQuery(sql);

            while(rs.next()){
                registro[0]= rs.getString("Id_funcionario");
                registro[1]= rs.getString("Nombre");
                registro[2]= rs.getString("CI");
                registro[3]= rs.getString("Correo");
                registro[4]= rs.getString("Cargo");
                registro[5]= rs.getString("Usuario");
                registro[6]= rs.getString("Clave");
                registro[7]= rs.getString("Fecha_ingreso");

                busqueda.addRow(registro);
            }
            vista.setModel(busqueda);
        }
        catch (SQLException e)
        {
            JOptionPane.showMessageDialog(null, e);

        }
    }//GEN-LAST:event_buscar_nombreActionPerformed

   
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(funcionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(funcionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(funcionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(funcionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new funcionario().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton agregar_funcionario;
    private javax.swing.JButton atras;
    private javax.swing.JButton buscar_nombre;
    private javax.swing.JTextField cargo_funcionario;
    private javax.swing.JTextField ci_funcionario;
    private javax.swing.JPasswordField clave_funcionario;
    private javax.swing.JTextField correo_funcionario;
    private javax.swing.JButton editar_funcionario;
    private javax.swing.JButton eliminar_funcionario;
    private javax.swing.JTextField funcionario_busqueda;
    private javax.swing.JTextField id_funcionario;
    private com.toedter.calendar.JDateChooser ingreso_funcionario;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField nombre_funcionario;
    private javax.swing.JButton nuevo_funcionario;
    private javax.swing.JTextField usuario_funcionario;
    private javax.swing.JTable vista;
    // End of variables declaration//GEN-END:variables

    private void llamarprincipal() {
      principal v=new principal();
      v.setVisible(true);
      v.setLocationRelativeTo(this);
      this.dispose();
    }

    private void llamar() {
    ConexionMySql con = new ConexionMySql();
        Connection cnn = con.conectar();
        String[] titulos = {"Id Funcionario","Nombre","Doc Identidad","Correo","Cargo","Usuario","Clave","Fecha de Ingreso"};
        busqueda = new DefaultTableModel(null,titulos);
        String [] registro = new String[9];
        String id = (funcionario_busqueda.getText());
        String sql = "SELECT Id_funcionario,Nombre,Ci,Correo,Cargo,Usuario,Clave,Fecha_ingreso FROM funcionario where nombre LIKE '%" + id +"%'";
        try
        {
            Statement st = cnn.createStatement();
            ResultSet rs = st.executeQuery(sql);

            while(rs.next()){
                registro[0]= rs.getString("Id_funcionario");
                registro[1]= rs.getString("Nombre");
                registro[2]= rs.getString("CI");
                registro[3]= rs.getString("Correo");
                registro[4]= rs.getString("Cargo");
                registro[5]= rs.getString("Usuario");
                registro[6]= rs.getString("Clave");
                registro[7]= rs.getString("Fecha_ingreso");

                busqueda.addRow(registro);
            }
            vista.setModel(busqueda);
        }
        catch (SQLException e)
        {
            JOptionPane.showMessageDialog(null, e);

        }    
    }
    String actualizar ="";
    private void PasarTabla(String valor) {
    ConexionMySql con = new ConexionMySql();
      Connection cnn = con.conectar();

      String sql = "SELECT Id_funcionario,Nombre,Ci,Correo,Cargo,Usuario,Clave,Fecha_ingreso FROM funcionario WHERE id_funcionario = "+ valor;
      try 
      {
        Statement st = cnn.createStatement();
        ResultSet rs = st.executeQuery(sql);
        if(rs.next()){
            id_funcionario.setText(rs.getString(1)) ;
            nombre_funcionario.setText(rs.getString(2));
            ci_funcionario.setText(rs.getString(3));
            correo_funcionario.setText(rs.getString(4));
            cargo_funcionario.setText(rs.getString(5));
            usuario_funcionario.setText(rs.getString(6));
            clave_funcionario.setText(rs.getString(7));
            ingreso_funcionario.setDate(rs.getDate(8));
          
        }
      } 
      catch (SQLException e) 
      {
            JOptionPane.showMessageDialog(null, e);
      }
      actualizar = valor;    
    }

    private void limpiar() {
        id_funcionario.setEnabled(true);
        nombre_funcionario.setEnabled(true);
        ci_funcionario.setEnabled(true);
        correo_funcionario.setEnabled(true);
        cargo_funcionario.setEnabled(true);
        usuario_funcionario.setEnabled(true);
        clave_funcionario.setEnabled(true);
        ingreso_funcionario.setEnabled(true);
        agregar_funcionario.setEnabled(true);
        eliminar_funcionario.setEnabled(true);
        editar_funcionario.setEnabled(true);
        
        id_funcionario.setText("");
        nombre_funcionario.setText("");
        ci_funcionario.setText("");
        correo_funcionario.setText("");
        cargo_funcionario.setText("");
        usuario_funcionario.setText("");
        clave_funcionario.setText("");
        ingreso_funcionario.setDate(null);
    }

    
}
